home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / menus / marxmenu / meter.inc < prev    next >
Text File  |  1996-07-10  |  2KB  |  71 lines

  1. Comment
  2. ========================================
  3.  
  4.  METER.INC
  5.  (c) Copyright 1990-1991 Computer Tyme * All rights reserved
  6.  
  7.  This software metering module counts how many users are using an
  8.  application and limits it to a fixed number of users. Thus, you can
  9.  save money on other software by limiting the number of people who can
  10.  run an application to the number of copies you own.
  11.  
  12.  This can also be used to limit an application to 1 user where the
  13.  application only works on a network if for one user at a time.
  14.  
  15.  To use this module, add the line INCLUDE 'METER.INC' to your menu.
  16.  Then under the OnKey you want to meter:
  17.  
  18.  OnKey 'W'
  19.     if Limit('WP',6) then Return   ;limit to 6 users
  20.     WP
  21.  
  22.  In the above example, a Word Perfect choice is limited to 6 users. Thus
  23.  you may have 20 users total but only 6 can run Word Perfect at the same
  24.  time.
  25.  
  26.  The way it works is, MarxMenu creates a semaphore when it runs an
  27.  application and stores the semaphore name in an environment variable
  28.  named METER. When the user returns to the menu the semaphore is
  29.  cleared. If the user turns off their computer in the middle of an
  30.  application, netware will clear the semaphore within 15 minutes.
  31.  
  32.  This file could be modified to create a report file to trace usage of
  33.  programs and when programs overflow. In the spirit of "keep it simple"
  34.  I have not included these features.
  35.  
  36. ========================================
  37. EndComment
  38.  
  39. MeterInit
  40.  
  41. Procedure MeterInit
  42. var SemaName
  43.    SemaName = ReadEnv('METER')
  44.    if SemaName > '' then NovCloseSemaphore('XM-' + SemaName)
  45.    SetEnv('METER=')
  46. EndProc
  47.  
  48.  
  49. Procedure Limit (Name,Count)
  50.    if NovSemaphoreUsers('XM-' + Name) >= Count
  51.       TooManyUsers(Name)
  52.       Return True
  53.    endif
  54.    NovOpenSemaphore('XM-' + Name,0) ; 'XM-' is for XMETER compatibility
  55.    SetEnv('METER=' + Name)
  56.    Return False
  57. EndProc
  58.  
  59.  
  60. Procedure TooManyUsers(Name)
  61. var Ch
  62.    BoxHeader = ' * Press any Key * '
  63.    DrawBox 11 21 length(Name) + 30 3
  64.    UseArrows Off
  65.    Cursor Off
  66.    TextColor MenuHeaderFG MenuBG
  67.    Write Char(7) ' All copies of ' Name ' are in Use!'
  68.    Ch = ReadKey
  69.    EraseTopWindow
  70. EndProc
  71.